package uniandes.moviles.antid.mundo;

import java.util.ArrayList;
import java.util.Date;

/**
 * Exercise routine that can be assigned to one or more patients.
 * @author estudiante
 *
 */
public class Routine {
	
	/**
	 * The unique identifier of the routine.
	 */
	private int id;
	
	/**
	 * The routine's exercises.
	 */
	private ArrayList<Exercise> exercises;
	
	/**
	 * Creates an instance of the routine.
	 */
	public Routine()
	{
		exercises = new ArrayList<Exercise>();		
	}
	
	/**
	 * Adds an exercise to the list of exercises.
	 * @param type The type of the exercise to add.
	 * @param dueDate The new exercise's due date.
	 */
	public void addExercise(String type, Date dueDate)
	{
		Exercise e = new Exercise(type, dueDate);
		exercises.add(e);		
	}
	
	/**
	 * Searches an exercise in the routine, by the name and due date of the particular exercise.
	 * @param dueDate The date that the exercise is due.
	 * @return
	 */
	public Exercise searchExercise(Date dueDate)
	{
		boolean encontrado = false;
		Exercise e = null;
		for (int i = 0; i < exercises.size()&&!encontrado; i++) 
		{
			Exercise exercise = exercises.get(i);
			if(exercise.getDueDate().equals(dueDate))
			{
				e = exercise;
				encontrado = true;
			}
		}
		return e;
	}
	
	/**
	 * Removes the exercise found in the specified date.
	 * @param dueDate The date the exercise to eras is due.
	 */
	public void deleteExercise(Date dueDate)
	{
		Exercise e = searchExercise(dueDate);
		exercises.remove(e);
	}

	/**
	 * Returns the id of the routine.
	 * @return the id
	 */
	public int getId() {
		return id;
	}

	/**
	 * Sets a new id to a routine.
	 * @param id the id to set
	 */
	public void setId(int id) {
		this.id = id;
	}

	/**
	 * Returns the list of exercises of the routine.
	 * @return the exercises
	 */
	public ArrayList<Exercise> getExercises() {
		return exercises;
	}

	/**
	 * Sets the list of exercises of the routine.
	 * @param exercises the exercises to set
	 */
	public void setExercises(ArrayList<Exercise> exercises) {
		this.exercises = exercises;
	}
	
	

}
